﻿using BUS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;
using System.Text;
using System.Security.Cryptography;
using OnlineDigitalCameraWebsite.Class;

namespace OnlineDigitalCameraWebsite
{
    public partial class DangNhap : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            UsersBUS uBUS = new UsersBUS();
            User u = new   DAO.User();
            u = uBUS.DangNhap(txtAccount.Text.Trim(), XuLy.MaHoaMatKhau(txtPasss.Text.Trim()));
            if(u == null)
            {
                lblTB.Text = "Sai tên đăng nhập hoặc mật khẩu.";
                lblTB.Visible = true;
            }
            else if (u.userStatus == false)
            {
                lblTB.Text = "Tài khoản đang bị khóa.";
                lblTB.Visible = true;
            }
            else
            {
                Session["DaDangNhap"] = true;
                Session["HoTen"] = u.userName;
                Session["LoaiThanhVien"] = u.roleId;
                Session["Username"] = u.userName;
                Session["Email"] = u.userEmail;
                Session["UserID"] = u.userId;
                if (u.roleId == 1)
                {
                    Response.Redirect("/Admin/Default.aspx");
                }
                else if (u.roleId == 2)
                {
                    Response.Redirect("/Users/Default.aspx");
                }
            }
        }
         

        protected void btnDangKy_Click(object sender, EventArgs e)
        {
            Response.Redirect("/DangKy.aspx");
        }
    }
}